package cn.flying.cloud.task.core.batch.reader;

import org.springframework.batch.item.file.ResourceAwareItemReaderItemStream;
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;

/**
 * 文件读取抽象类
 *
 * @author: admin
 * @date: 2024年02月18日 15:20
 * @version: 1.0
 */
public class AbstractFileReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ResourceAwareItemReaderItemStream<T>, InitializingBean {

    protected Resource resource;
    protected Class<T> mapperClass;

    /**
     * Read next item from input.
     *
     * @return an item or {@code null} if the data source is exhausted
     * @throws Exception Allows subclasses to throw checked exceptions for interpretation by the framework
     */
    @Override
    protected T doRead() throws Exception {
        return null;
    }

    /**
     * Open resources necessary to start reading input.
     *
     * @throws Exception Allows subclasses to throw checked exceptions for interpretation by the framework
     */
    @Override
    protected void doOpen() throws Exception {

    }

    /**
     * Close the resources opened in {@link #doOpen()}.
     *
     * @throws Exception Allows subclasses to throw checked exceptions for interpretation by the framework
     */
    @Override
    protected void doClose() throws Exception {

    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }

    public Resource getResource() {
        return resource;
    }

    @Override
    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public Class<T> getMapperClass() {
        return mapperClass;
    }

    public void setMapperClass(Class<T> mapperClass) {
        this.mapperClass = mapperClass;
    }
}
